﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace MulticastTV
{
    /// <summary>
    /// Form for playlist import.
    /// </summary>
    public partial class ImportChannelsForm : Form
    {
        static string path = Application.StartupPath;
        string appath;
        char[] dotdelimiter = { '.' };
        DirectoryInfo dir;
        FileInfo[] files;
        
        public ImportChannelsForm(string apdatapath)
        {
            InitializeComponent();
            appath = apdatapath;
        }

        private void Form5_Load(object sender, EventArgs e)
        {
            if (Directory.Exists(path+@"\import"))
            {
                dir = new DirectoryInfo(path + @"\import");
                files = dir.GetFiles("*.atvlist");

                foreach (FileInfo file in files)
                {
                    String fileName = file.Name.Split(dotdelimiter)[0];
                    comboBox1.Items.Add(fileName);
                }

                // select first one
                if (comboBox1.Items.Count > 0)
                {
                    comboBox1.SelectedIndex = 0;
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Items.Count > 0 && comboBox1.SelectedIndex != -1)
            {
                if (File.Exists(path + @"\import\" + comboBox1.SelectedItem.ToString() + ".atvlist"))
                {
                    if (!Directory.Exists(appath + @"\..\"))
                        Directory.CreateDirectory(appath + @"\..\");
                    File.Copy(path + @"\import\" + comboBox1.SelectedItem.ToString() + ".atvlist", appath + @"\..\import.atvlist");
                }
                this.Close();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
